import api from "@/api/api";
var localTimeOut, netHeadUrl, reportHeadUrl, localHeadUrl, photoHeadUrl, photoHeadUrlCheck, ylocalHeadUrl,
	capitalHeadUrl, rosideudpHeadUrl, smsHeadUrl, auditHeadUrl, spacelockHeadUrl, messageHeadUrl;
export default class {
	constructor(config) {
		localTimeOut = 8000;
		netHeadUrl = config.getNetHeadUrl();
		reportHeadUrl = config.getReportHeadUrl();
		localHeadUrl = config.getLocalHeadUrl();
		photoHeadUrl = config.getPhotoHeadUrl();
		photoHeadUrlCheck = config.getPhotoHeadUrlCheck();
		ylocalHeadUrl = config.getYlocalHeadUrl();
		capitalHeadUrl = config.getCapitalHeadUrl();
		rosideudpHeadUrl = config.getRosideudpHeadUrl();
		smsHeadUrl = config.getSmsHeadUrl();
		auditHeadUrl = config.getAuditHeadUrl();
		spacelockHeadUrl = config.getSpacelockHeadUrl();
		messageHeadUrl = config.getMessageHeadUrl();
	}

	getLoginQrImage() {
		let serial = "manage" + Date.parse(new Date()) + Math.floor(Math.random() * 90000000 + 10000000);
		return api.postUrl(true, netHeadUrl + "/wxQRLogin/loginSerial", {
			loginSerial: serial
		}, true);
	}

	/**
	 * 发起get请求
	 * @param {Boolean} isShowLoading 是否显示加载框
	 * @param {String} url
	 * @param {Object} param 传参
	 * @return {Promise} then(data) 成功返回data(结果数据)
	 * @return {Promise} catch(reason) 失败返回reason(失败原因)
	 */
	get(isShowLoading, url, param, userId, linkId) {
		return api.getUrl(isShowLoading, netHeadUrl + url, param, false, null, linkId);
	}

	delete(isShowLoading, url, param, userId, linkId) {
		return api.deleteUrl(isShowLoading, netHeadUrl + url, param, false, null, linkId);
	}

	put(isShowLoading, url, param, userId, linkId) {
		return api.putUrl(isShowLoading, netHeadUrl + url, param, false, null, linkId);
	}

	//临时地磁编号
	postRosideudp(isShowLoading, url, param, userId, linkId) {
		return api.postUrl(isShowLoading, rosideudpHeadUrl + url, param, false, null, linkId);
	}

	getRosideudp(isShowLoading, url, param, userId, linkId) {
		return api.getUrl(isShowLoading, rosideudpHeadUrl + url, param, false, null, linkId);
	}

	getCity(isShowLoading, url, param, userId, linkId) {
		return api.getUrl(isShowLoading, url, param, false, null, linkId);
	}

	// 路内
	getRoad(isShowLoading, url, param, userId, linkId) {
		return new Promise(function (resolve, reject) {
			let paramUrl = api.getApp().getRoadRoleUrl();
			if (!paramUrl) {
				reject("暂无路内数据");
				return;
			}
			api.getUrl(isShowLoading, paramUrl + url, param, false, null, linkId).then(function (data) {
				resolve(data);
			}).catch(function (reason) {
				reject(reason);
			});
		});
	}

	postRoad(isShowLoading, url, param, userId, linkId) {
		return new Promise(function (resolve, reject) {
			let paramUrl = api.getApp().getRoadRoleUrl();
			if (!paramUrl) {
				reject("暂无路内数据");
				return;
			}
			api.postUrl(isShowLoading, paramUrl + url, param, false, null, linkId).then(function (data) {
				resolve(data);
			}).catch(function (reason) {
				reject(reason);
			});
		});
	}

	putRoad(isShowLoading, url, param, userId, linkId) {
		return new Promise(function (resolve, reject) {
			let paramUrl = api.getApp().getRoadRoleUrl();
			if (!paramUrl) {
				reject("暂无路内数据");
				return;
			}
			api.putUrl(isShowLoading, paramUrl + url, param, false, null, linkId).then(function (data) {
				resolve(data);
			}).catch(function (reason) {
				reject(reason);
			});
		});
	}

	deleteRoad(isShowLoading, url, param, userId, linkId) {
		return new Promise(function (resolve, reject) {
			let paramUrl = api.getApp().getRoadRoleUrl();
			if (!paramUrl) {
				reject("暂无路内数据");
				return;
			}
			api.deleteUrl(isShowLoading, paramUrl + url, param, false, null, linkId).then(function (data) {
				resolve(data);
			}).catch(function (reason) {
				reject(reason);
			});
		});
	}

	// 短信
	getSms(isShowLoading, url, param, userId, linkId) {
		return api.getUrl(isShowLoading, smsHeadUrl + url, param, false, null, linkId);
	}

	postSms(isShowLoading, url, param, userId, linkId) {
		return api.postUrl(isShowLoading, smsHeadUrl + url, param, false, null, linkId);
	}

	postRoadLocal(isShowLoading, url, param, linkId) {
		var page = this;
		linkId = api.isDebugMode() ? '119761632728449025' : linkId;
		return new Promise(function (resolve, reject) {
			page.getRoleUrl(linkId, function (isSuccess, roadData) {
				if (isSuccess) {
					api.postUrl(isShowLoading, roadData + url, param, false, null, linkId).then(function (data) {
						resolve(data);
					}).catch(function (reason) {
						reject(reason);
					});
				} else {
					reject(roadData);
				}
			});
		});
	}

	getRoadLocal(isShowLoading, url, param, linkId) {
		var page = this;
		return new Promise(function (resolve, reject) {
			page.getRoleUrl(linkId, function (isSuccess, roadData) {
				if (isSuccess) {
					api.getUrl(isShowLoading, roadData + url, param, false, null, linkId).then(function (data) {
						resolve(data);
					}).catch(function (reason) {
						reject(reason);
					});
				} else {
					reject(roadData);
				}
			});
		});
	}

	getRoleUrl(linkId, callback) {
		api.getApp().loginRole(linkId).then(function (data) {
			callback(true, data);
		}).catch(function (reason) {
			callback(false, reason);
		});
	}

	//头key为authdst
	get2(isShowLoading, url, param) {
		return api.getUrl(isShowLoading, netHeadUrl + url, param);
	}

	/**
	 * 发起post请求
	 * @param {Boolean} isShowLoading 是否显示加载框
	 * @param {String} url
	 * @param {Object} param 传参
	 * @param {Number} userId 头部的用户Id，可不传
	 * @param {Number} linkId 头部的关联Id，可不传
	 * @return {Promise} then(data) 成功返回data(结果数据)
	 * @return {Promise} catch(reason) 失败返回reason(失败原因)
	 */
	post(isShowLoading, url, param, userId, linkId) {
		return api.postUrl(isShowLoading, netHeadUrl + url, param, false, null, linkId);
	}

	post1(isShowLoading, url, param, userId, linkId) {
		return api.postUrl(isShowLoading, photoHeadUrl + url, param, false, null, linkId);
	}

	//头key为authdst
	post2(isShowLoading, url, param) {
		return api.postUrl(isShowLoading, netHeadUrl + url, param);
	}
	//特殊使用不用校验token
	post3(isShowLoading, url, param) {
		return api.postUrl(isShowLoading, netHeadUrl + url, param, true);
	}

	/**
	 * 发起本地get请求
	 * @param {Boolean} isShowLoading 是否显示加载框
	 * @param {String} url
	 * @param {Object} param 传参
	 * @return {Promise} then(data) 成功返回data(结果数据)
	 * @return {Promise} catch(reason) 失败返回reason(失败原因)
	 */
	getLocal(isShowLoading, url, param) {
		return api.getUrl(isShowLoading, localHeadUrl + url, param, false, localTimeOut);
	}

	//动态匹配本地ip
	getLocal2(isShowLoading, localUrl, url, param) {
		return api.getUrl(isShowLoading, localUrl + url, param, false, localTimeOut);
	}

	//动态匹配本地ip
	putLocal2(isShowLoading, localUrl, url, param) {
		return api.putUrl(isShowLoading, localUrl + url, param, false, localTimeOut);
	}

	/**
	 * 发起本地post请求
	 * @param {Boolean} isShowLoading 是否显示加载框
	 * @param {String} url
	 * @param {Object} param 传参
	 * @param {Number} userId 头部的用户Id，可不传
	 * @param {Number} linkId 头部的关联Id，可不传
	 * @return {Promise} then(data) 成功返回data(结果数据)
	 * @return {Promise} catch(reason) 失败返回reason(失败原因)
	 */
	postLocal(isShowLoading, url, param, userId, linkId) {
		return api.postUrl(isShowLoading, localHeadUrl + url, param, false, localTimeOut, linkId);
	}

	postYLocal(isShowLoading, url, param, linkId) {
		return api.postUrl(isShowLoading, ylocalHeadUrl + url, param, false, localTimeOut, linkId);
	}

	getYLocal(isShowLoading, url, param, userId, linkId) {
		return api.getUrl(isShowLoading, ylocalHeadUrl + url, param, false, null, linkId);
	}


	//动态匹配本地ip
	postLocal2(isShowLoading, localUrl, url, param, userId, linkId) {
		return api.postUrl(isShowLoading, localUrl + url, param, false, localTimeOut, linkId);
	}

	//图片地址上传post(单图片)
	postAddPhoto(isShowLoading, url, md5, file) {
		var param = new FormData();
		param.append(md5, file, file.name);
		return api.uploadFile(isShowLoading, photoHeadUrl + url, null, null, param);
	}

	//图片地址上传post(多图片)
	postAddManyPhoto(isShowLoading, url, param) {
		return api.uploadFile(isShowLoading, photoHeadUrl + url, null, null, param);
	}

	//图片地址删除post
	postDelPhoto(isShowLoading, url, param) {
		return api.postUrl(isShowLoading, photoHeadUrl + url, param);
	}

	//删除商城图片
	deletePhoto(isShowLoading, url, param, userId, linkId) {
		return api.deleteUrl(isShowLoading, photoHeadUrl + url, param, false, null, linkId);
	}

	//图片地址get
	getPhoto(isShowLoading, url, param) {
		return api.getUrl(isShowLoading, photoHeadUrl + url, param);
	}
	// 报表对账
	getReconciliation(isShowLoading, url, param, userId, linkId, timeOut) {
		return api.getUrl(isShowLoading, photoHeadUrlCheck + url, param, false, timeOut, linkId);
	}

	postReconciliation(isShowLoading, url, param, userId, linkId, timeOut) {
		return api.postUrl(isShowLoading, photoHeadUrlCheck + url, param, false, timeOut, linkId);
	}

	/**
	 * 发起本地put请求
	 * @param {Boolean} isShowLoading 是否显示加载框
	 * @param {String} url
	 * @param {Object} param 传参
	 * @return {Promise} then(data) 成功返回data(结果数据)
	 * @return {Promise} catch(reason) 失败返回reason(失败原因)
	 */

	putLocal(isShowLoading, url, param) {
		return api.putUrl(isShowLoading, localHeadUrl + url, param, false, localTimeOut);
	}

	/**
	 * 发起报表get请求
	 * @param {Boolean} isShowLoading 是否显示加载框
	 * @param {String} url
	 * @param {Object} param 传参
	 * @return {Promise} then(data) 成功返回data(结果数据)
	 * @return {Promise} catch(reason) 失败返回reason(失败原因)
	 */
	getReport(isShowLoading, url, param) {
		return api.getUrl(isShowLoading, reportHeadUrl + url, param);
	}
	getReport2(isShowLoading, url, param, userId, linkId, timeOut) {
		return api.getUrl(isShowLoading, reportHeadUrl + url, param, false, timeOut, linkId);
	}

	/**
	 * 发起报表post请求
	 * @param {Boolean} isShowLoading 是否显示加载框
	 * @param {String} url
	 * @param {Object} param 传参
	 * @param {Number} userId 头部的用户Id，可不传
	 * @param {Number} linkId 头部的关联Id，可不传
	 * @return {Promise} then(data) 成功返回data(结果数据)
	 * @return {Promise} catch(reason) 失败返回reason(失败原因)
	 */
	postReport(isShowLoading, url, param) {
		return api.postUrl(isShowLoading, reportHeadUrl + url, param);
	}

	//车场商店
	getCapital(isShowLoading, url, param, userId, linkId) {
		return api.getUrl(isShowLoading, capitalHeadUrl + url, param, false, null, linkId);
	}

	postCapital(isShowLoading, url, param, userId, linkId) {
		return api.postUrl(isShowLoading, capitalHeadUrl + url, param, false, null, linkId);
	}

	//停车币，用户钱包
	getParkM(isShowLoading, url, param, userId) {
		return api.getUrl(isShowLoading, capitalHeadUrl + url, param);
	}

	//我的车辆
	getMyCar(isShowLoading, url, param, userId) {
		return api.getUrl(isShowLoading, netHeadUrl + url, param);
	}

	//审核
	postAudit(isShowLoading, url, param, userId, linkId) {
		return api.postUrl(isShowLoading, auditHeadUrl + url, param, false, userId, linkId);
	}

	getAudit(isShowLoading, url, param, userId, linkId) {
		return api.getUrl(isShowLoading, auditHeadUrl + url, param, false, userId, linkId);
	}

	//共享车位设备管理
	postSpacelock(isShowLoading, url, param, userId, linkId) {
		return api.postUrl(isShowLoading, spacelockHeadUrl + url, param, false, null, linkId);
	}

	getSpacelock(isShowLoading, url, param, userId, linkId) {
		return api.getUrl(isShowLoading, spacelockHeadUrl + url, param, false, null, linkId);
	}

	// 进出场通知管理
	getMessage(isShowLoading, url, param, userId, linkId) {
		return api.getUrl(isShowLoading, messageHeadUrl + url, param, false, null, linkId);
	}

	postMessage(isShowLoading, url, param, userId, linkId) {
		return api.postUrl(isShowLoading, messageHeadUrl + url, param, false, null, linkId);
	}

	getReverseData(isShowLoading, url, linkId) {
		return api.getUrl(isShowLoading, netHeadUrl + url, {
			enterpriseId: linkId
		}, null, null, linkId);
	}

	// linkId 机构id
	getReserveParkList(isShowLoading, url, linkId) {
		return api.getUrl(isShowLoading, ylocalHeadUrl + url, {
			bussinessId: linkId
		}, null, null, linkId)
	}

	getReverseParkData(isShowLoading, url, parkId, linkId) {
		return api.getUrl(isShowLoading, netHeadUrl + url, {
			parkId: parkId
		}, null, null, linkId);
	}

	getParkListByEnterpriseId(isShowLoading, url, linkId) {
		return api.getUrl(isShowLoading, netHeadUrl + url, {
			page: 1,
			pageSize: 10000,
			agent: 0,
		});
	}

	// 系统大屏满意度
	getClientSatisfaction(isShowLoading) {
		return api.getUrl(isShowLoading, auditHeadUrl + '/report/question/satisfaction', );
	}

	// 验证用户角色权限
	validRole(isShowLoading, linkId, role, userId) {
		return api.postUrl(isShowLoading, netHeadUrl + "/role/select", {
			linkID: linkId,
			role: role,
			userID: userId,
		})
	}

	// 上传个人的图片
	uploadPersonImageFile(isShowLoading, file) {
		let formData = new FormData();
		formData.append("serviceId", api.getAccountCodeSync());
		formData.append("file", file);
		formData.append("serviceType", 1);
		let photoUrl = api.getAppConfig().getPhotoHeadUrl()
		return api.uploadFile(isShowLoading, photoUrl + "/service/file/upload", null, null, formData);
	}

	// 上传图片文件
	uploadEnterpriseImageFile(isShowLoading, enterpriseId, file) {
		let formData = new FormData();
		formData.append("serviceId", enterpriseId);
		formData.append("file", file);
		let photoUrl = api.getAppConfig().getPhotoHeadUrl()
		return api.uploadFile(isShowLoading, photoUrl + "/service/file/upload", null, null, formData);
	}

	// 获取限时免费车列表（单车场）
	getLimitRentList(isShowLoading, param) {
		var param = param;
		return api.getUrl(isShowLoading, netHeadUrl + "/limit/rent/list", param);
	}

	// 获取限时免费车列表（单车场）
	//param:page  pageSize   carNo
	getLimitRentUserList(isShowLoading, param) {
		var param = param;
		return api.getUrl(isShowLoading, netHeadUrl + "/limit/rent/user/list", param);
	}


	// 获取限时免费车详情
	// 传carNo  enterpriseId
	getLimitRentDetail(isShowLoading, param) {
		return api.getUrl(isShowLoading, netHeadUrl + "/limit/rent/detail", param);
	}

	// 删除限时免费车
	deleteLimitRent(isShowLoading, timeLimitRentModels) {
		return api.postUrl(isShowLoading, netHeadUrl + "/limit/rent/del",
			timeLimitRentModels
		);
	}

	// 获取免费车列表
	// type 0=全部 1=已开启 2=未开启
	// carNo 车牌号
	// phone 手机号
	// name 姓名
	// order 组别
	getFreeRentList(isShowLoading, param) {
		// var param = param;
		return api.getUrl(isShowLoading, netHeadUrl + "/free/rent/list", param);
	}

	// 删除限时免费车
	deleteFreeRent(isShowLoading, freeRentModels) {
		return api.postUrl(isShowLoading, netHeadUrl + "/free/rent/del",
			freeRentModels
		);
	}

	// 获取巡查员统计报表数据
	getSettleListByroad(isShowLoading, params, linkId, url) {
		return api.getUrl(isShowLoading, url + '/rosideorder/manager/settlelistbyroad', {
			page: params.page,
			pageSize: params.pageSize,
			startTime: params.startTime,
			endTime: params.endTime
		}, false, null, linkId);
	}

	// 新增广告
	createAdvertisement(isShowLoading, enterpriseAdModel) {
		return api.postUrl(isShowLoading, netHeadUrl + "/enterprisead/ad/create",
			enterpriseAdModel
		);
	}

	// 广告显示位置列表
	getDisplayList(isShowLoading) {
		return api.getUrl(isShowLoading, netHeadUrl + "/enterprisead/display/list");
	}

	// 获取广告列表
	getAdList(isShowLoading, param) {
		return api.getUrl(isShowLoading, netHeadUrl + "/enterprisead/ad/list", param);
	}

	// 删除广告列表
	deleteAd(isShowLoading, countId) {
		return api.postUrl(isShowLoading, netHeadUrl + "/enterprisead/ad/delete", {
			countId: countId
		});
	}

	// 获取车场列表
	getUserEnterpriset(isShowLoading, name) {
		if (!name) {
			name = "";
		}
		return api.getUrl(isShowLoading, netHeadUrl + "/userenterprise/zklist", {
			name: name
		});
	}

	// 更新广告信息
	updateAd(isShowLoading, enterpriseAdModel) {
		return api.postUrl(isShowLoading, netHeadUrl + "/enterprisead/ad/update", enterpriseAdModel);
	}

	// 广告详情
	getAdDetail(isShowLoading, param) {
		return api.getUrl(isShowLoading, netHeadUrl + "/enterprisead/ad/visit/list", param);
	}

	// 获取目的地附近车场
	getAddrNearPark(isShowLoading, latitude, longitude, address) {
		return api.getUrl(isShowLoading, netHeadUrl + "/roside/near/park", {
			latitude: latitude,
			longitude: longitude,
			addr: address
		});
	}

	// 广告详情导出
	exportAdVisit(isShowLoading, param) {
		return api.getUrl(isShowLoading, netHeadUrl + "/enterprisead/export/visit/list", {
			countId: param.countId, // 广告id
			enterpriseName: param.enterpriseName, // 机构名
			startTime: param.startTime, // 开始时间
			endTime: param.endTime, // 结束时间
		});
	}

	// 白名单查询搜索
	// page: param.page,
	// pageSize: param.pageSize,
	// type: param.type, // "1全城 2特定 3特殊车场"
	// carNo: param.carNo, // 车牌号
	// areaId: param.areaId, // 路段id
	// enterpriseId: param.enterpriseId, // 车场id
	// areaId: param.areaName, // 路段名
	// enterpriseId: param.enterpriseName, // 车场名
	whiteListSearch(isShowLoading, param) {
		return api.getUrl(isShowLoading, netHeadUrl + "/rent2/white/serch", param);
	}

	//    page: param.page,
	// 		pageSize: param.pageSize,
	// 		bussinessId:param.bussinessId, // 机构
	// 		carNo: param.carNo, // 车牌号
	// 		option: param.option, // 1到期时间 2导入时间
	// 		startTime: param.startTime, // 开始时间
	// 		endTime: param.endTime, // 结束时间
	whiteCarSearch(isShowLoading, param) {
		return api.getUrl(isShowLoading, netHeadUrl + "/rent2/white/list", param);
	}


	// 白名单详情查看
	getWhiteDetail(isShowLoading, roadIds) {
		return api.getUrl(isShowLoading, netHeadUrl + "/rent2/white/detail", roadIds);
	}

	// 获取操作日志
	getOperateRecord(isShowLoading, param) {
		return api.getUrl(isShowLoading, netHeadUrl + "/rent2/operate/record", param);
	}

	// 获取绑定车辆列表--统计
	getBindCarList(isShowLoading, param) {
		return api.getUrl(isShowLoading, reportHeadUrl + "/user/bind/carno/list", param);
	}

	// 获取绑定车辆列表-明细
	getBindCarList2(isShowLoading, param) {
		return api.getUrl(isShowLoading, netHeadUrl + "/generalization/bind/carno/list", param);
	}

	// 获取分析详细数据
	getAnalyDetail(isShowLoading, param) {
		return api.getUrl(isShowLoading, reportHeadUrl + "/analy/detail", param);
	}

	// 获取概况分析数据
	getAnalySurvey(isShowLoading, param) {
		return api.getUrl(isShowLoading, reportHeadUrl + "/analy/survey", param);
	}

	// 获取车场列表
	getParkbyEnterprise(isShowLoading, enterpriseId) {
		return api.getUrl(isShowLoading, netHeadUrl + "/parkbasicinfo/getparkbyenterprise/" + enterpriseId);
	}
}